package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Userinfo;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.query.UserQueryObject;
import cn.wolfcode.crm.service.IUserinfoService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("userinfo")
public class UserinfoController {

    @Autowired
    private IUserinfoService userinfoService;

    @RequestMapping("list")
    @ResponseBody
    public List<Userinfo> list() {
        return userinfoService.selectAll();
    }

    @RequestMapping("view")
    public String query(QueryObject qo) {
        return "userinfo";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Userinfo userinfo) {
        JSONResult result = new JSONResult();
        try {
            userinfoService.saveOrUpdate(userinfo);
        } catch (Exception e) {
            result.remark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("audit")
    @ResponseBody
    public JSONResult audit(Long id) {
        JSONResult result = new JSONResult();
        try {
            userinfoService.audit(id);
        } catch (Exception e) {
            result.remark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult userinfo(QueryObject qo) {
        return userinfoService.query(qo);
    }
}
